import math
def define_next_permutation():
    global res
    for i in range(a - 1, -1, -1):
        if  res[i] > res[i - 1]:
            num_to_be_replaced= i - 1
            #print('num_to_be_replaced:', i - 1)
            break
    for j in range(a - 1, num_to_be_replaced, -1):
        if res[j] > res[num_to_be_replaced] :
            num_to_replace = j
            #print('num_to_replace', j)
            break
    temp = res[num_to_be_replaced]
    res[num_to_be_replaced] = res[num_to_replace]
    res[num_to_replace] = temp
    #res[num_to_be_replaced + 1:].reverse()
    res = res[:num_to_be_replaced + 1] + res[:num_to_be_replaced:- 1]
    print(''.join([str(i)  for i in res]))

a = int(input())
res = [i for i in range(1, a + 1)]
print(''.join([str(i)  for i in res]))
for i in range(math.factorial(a) - 1):
    define_next_permutation()
#print(math.factorial(a))